package com.longrise.android.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.common.utils.NetUtil;

/**
 * Created by sujizhong on 16/6/15.
 */
public class LoadOutDialog extends Dialog {

    private onLoadOutCallback mOnLoadOutCallback = null;

    public LoadOutDialog(Activity context, onLoadOutCallback onLoadOutCallback) {
        super(context, R.style.Dialog_Translucent_NoTitle);
        this.mOnLoadOutCallback = onLoadOutCallback;
        setCanceledOnTouchOutside(false);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_loadout);
        Window window = getWindow();
        window.setGravity(Gravity.CENTER);

        init();
    }

    private void init() {
        if (NetUtil.isNetWorkType(getContext()).equals("")) {
            TextView text_hint = (TextView) findViewById(R.id.text_network_msg);
            text_hint.setVisibility(View.VISIBLE);
        }
        findViewById(R.id.text_reload).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if (mOnLoadOutCallback != null) {
                        mOnLoadOutCallback.onLoadOutRefruch();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mOnLoadOutCallback != null) {
                mOnLoadOutCallback.onBack(event);
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    public interface onLoadOutCallback {

        void onLoadOutRefruch();

        void onBack(KeyEvent event);
    }

}
